package com.wnhz.work.yz.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TableRow;
import android.widget.TextView;

import com.bigkoo.pickerview.OptionsPickerView;
import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.R;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class CreatOrderActivity extends BaseActivity implements View.OnClickListener {
    private TableRow select_radio;
    private TextView radio;
    private TextView init_price, finish_price;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_creat_order);
        initTilte();
        initView();
    }

    private void initView() {
        select_radio = (TableRow) findViewById(R.id.select_radio);
        select_radio.setOnClickListener(this);
        radio = (TextView) findViewById(R.id.radio);
        init_price = (TextView) findViewById(R.id.init_price);
        finish_price = (TextView) findViewById(R.id.finish_price);

    }

    private void initTilte() {
        TextView title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("生成订单");
        findViewById(R.id.submit).setOnClickListener(this);
        findViewById(R.id.submit).setVisibility(View.VISIBLE);
        findViewById(R.id.btn_main_left).setOnClickListener(this);
        TextView right = (TextView) findViewById(R.id.submit);
        right.setText("下一步");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;
            case R.id.submit:
                Intent intent2 = new Intent(this, CreatOrderActivity.class);
                startActivity(intent2);
                break;
            case R.id.select_radio:
                initCustomOptionPicker();
                break;
        }
    }


    private void initCustomOptionPicker() {//条件选择器初始化，自定义布局
        final List<String> radios = new ArrayList<>();
        radios.clear();
        final DecimalFormat df = new DecimalFormat("######0.0");
        for (int i = 0; i < 10; i++) {
            radios.add(df.format(0.5 * (i + 2)));
        }

        OptionsPickerView pvOptions = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {
                radio.setText(radios.get(options1));
                finish_price.setText("￥"+df.format(Double.parseDouble(init_price.getText().toString().substring(1, init_price.getText().toString().length())) * Double.parseDouble(radios.get(options1))));
            }
        }).setTitleSize(16)//标题文字大小
                .setTitleText("预算系数")
                .setTitleBgColor(Color.WHITE)//标题背景颜色 Night mode
                .setTitleColor(getResources().getColor(R.color.text))//标题文字颜色)//标题文字颜色
                .setSubmitColor(getResources().getColor(R.color.main_color))//确定按钮文字颜色
                .setCancelColor(getResources().getColor(R.color.main_color))//取消按钮文字颜色
                .build();
        pvOptions.setPicker(radios);
        pvOptions.show();

    }
}
